unit Alta_Clientes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Mask, DBCtrls, Buttons;

type
  TF_Alta_Clientes = class(TForm)
    ADOConnection1: TADOConnection;
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    B_Accept: TButton;
    B_Cancel: TButton;
    GB_DatosReqEmp: TGroupBox;
    GB_DatosOpc: TGroupBox;
    Label1: TLabel;
    N: TLabel;
    Label4: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    DataSourceClientes: TDataSource;
    BB_CodEstado: TBitBtn;
    BB_CP: TBitBtn;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit9: TDBEdit;
    DBEdit10: TDBEdit;
    procedure B_AcceptClick(Sender: TObject);
    procedure B_CancelClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BB_CPClick(Sender: TObject);
    procedure DBEdit8Exit(Sender: TObject);
    procedure DBEdit9Exit(Sender: TObject);
    procedure BB_CodEstadoClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_Alta_Clientes: TF_Alta_Clientes;

implementation

uses Clientes, Localidades, Estado_Clientes;

{$R *.dfm}

procedure TF_Alta_Clientes.BB_CodEstadoClick(Sender: TObject);
begin
    F_EstadoClientes.Bandera_Seleccionar := True;
    F_EstadoClientes.ShowModal;
end;

procedure TF_Alta_Clientes.BB_CPClick(Sender: TObject);
begin
    F_Localidades.Bandera_Seleccionar := True;
    F_Localidades.Llama := 2;
    F_Localidades.showmodal;
end;

procedure TF_Alta_Clientes.B_AcceptClick(Sender: TObject);
begin
{ TRIM() Es para limpiar los espacios en blanco, sino '     ' me lo tomaba como dato }
  if ((TRIM(DBEdit1.Text) = '') OR (TRIM(DBEdit2.Text) = '') OR (TRIM(DBEdit6.Text) = '') OR (TRIM(DBEdit4.Text) = '') OR (TRIM(DBEdit8.Text) = '') OR (TRIM(DBEdit9.Text) = '')) THEn
    ShowMessage('Debe completar todos los datos requeridos.')
  ELSE
  BEGIN
    F_Clientes.T_Buscar.Text := F_Clientes.ADOQuery1APELLIDO_CLIENTE.Text;
    DataSourceClientes.DataSet.Append;
    F_Clientes.B_Buscar.Click;
    {DataSourceClientes.DataSet.Refresh;}
    F_Alta_Clientes.Close;
  END;
end;

procedure TF_Alta_Clientes.B_CancelClick(Sender: TObject);
begin
  DataSourceClientes.DataSet.Cancel;
  F_Alta_Clientes.Close;
  DataSourceClientes.DataSet.First;
end;

procedure TF_Alta_Clientes.DBEdit8Exit(Sender: TObject);
begin
  if TRIM(Self.DBEdit8.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM LOCALIDADES WHERE (COD_POSTAL = '+Self.DBEdit8.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_CP.Click;
    end
  END
  ELSE
     BB_CP.Click;

end;

procedure TF_Alta_Clientes.DBEdit9Exit(Sender: TObject);
begin

  if TRIM(Self.DBEdit9.Text) <> '' then
  BEGIN
    ADOQuery1.SQL.Text := 'SELECT * FROM ESTADO_CLIENTES WHERE (COD_ESTADO = '+Self.DBEdit9.Text+')';
    ADOQuery1.Open;
    if (BoolToStr(ADOQuery1.IsEmpty) = '-1') then
    begin
        BB_CodEstado.Click;
    end
  END
  ELSE
     BB_CodEstado.Click;
end;

procedure TF_Alta_Clientes.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DataSourceClientes.DataSet.Cancel;
end;

end.
